package com.itheima.d4_synchronized_method;

public class Account2 {
    private String accountID;//卡号
    private double money;//余额

    public Account2(String accountID, double money) {
        this.accountID = accountID;
        this.money = money;
    }

    //省略getter、setter方法

    //取钱
    public synchronized void drawMoney(double money) {
        Thread thread = Thread.currentThread();
         String name = thread.getName();

        if (this.money >= money) {
            //账户余额充足

            System.out.println(name + "成功取钱:" + money);
            this.money -= money;

            System.out.println("账户余额为：" + this.money);
        } else {
            System.out.println(name + "取款失败,余额不足！！");
        }


    }

    @Override
    public String toString() {
        return "Account{" +
                "accountID='" + accountID + '\'' +
                ", money=" + money +
                '}';
    }
}
